import zmq

SUBSCRIBERS_ECPECTED = 2


def main():
    context = zmq.Context()

    publisher = context.socket(zmq.PUB)
    publisher.bind("tcp://*:5561")

    syncservice = context.socket(zmq.REP)
    syncservice.bind("tcp://*:5562")

    subscribers = 0
    while subscribers < SUBSCRIBERS_ECPECTED:
        msg = syncservice.recv()
        syncservice.send(b'')
        subscribers += 1
        print("+1 subscriber (%i%i)" % (subscribers, SUBSCRIBERS_ECPECTED))

    for i in range(10):
        publisher.send(b'Rhubarb')

    publisher.send(b'END')


if __name__ == "__main__":
    main()
